home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12334 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  62 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP!!! -very important-- #3
  5. Date: Sat, 30 Mar 96 17:57:31 GMT
  6. Organization: none
  7. Message-ID: <828208651snz@genesis.demon.co.uk>
  8. References: <1996Mar21.001800.138165@forest>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <1996Mar21.001800.138165@forest>
  15.            groy@forest.drew.edu "I can't think of a nickname" writes:
  16.  
  17. >This is the last one (for a while nayway.. ) I promise.. ;)
  18. >I am trying to write a program that will take in any input.. and count up 
  19. >the numbers of characters... words and lines... it just doesn't want to 
  20. >work... help??
  21. >
  22. >#include<stdio.h>
  23. >#include<ctype.h>
  24. >
  25. >int main()  {
  26. >   int words = 0; /* number of words */
  27. >   int lines = 0; /* number of lines */
  28. >   int characters = 0; /* number of characters */
  29. >   char input; /* the area of input */
  30. >   int check_letter(char input); /* function that will check characters */
  31. >   int check_lines(char input); /* function that will check lines */
  32.  
  33. It is a good rule to put all function declarations at file scope (i.e.
  34. not within other functions). This ebsures that the compiler will validate
  35. them correctly.
  36.  
  37. >   int whitespace = 1;
  38. >
  39. >
  40. >   printf("type in any group of words, lines, characters that you wish");
  41. >   printf("\nthen the computer will display the amount of words, lines");
  42. >   printf("\nand characters (ignoring any white-space) that you may\n");
  43. >   printf("type in.   <<press cntrl-d when done>> \n");
  44. >
  45. >   while ((scanf("%c",&input)) != EOF)
  46. >     {
  47. >      characters += isalnum(input);
  48.  
  49. Presumably characters here is actually a count of alpha-numeric characters,
  50. not characters in general.
  51.  
  52. You problem is that ctype.h functions/macros don't in general return 0 or 1
  53. they return zero or nonzero. A common implemenation is to use bit masking
  54. on a lookup table which gives a very strong possibility of not returning
  55. 1 on a match.
  56.  
  57. -- 
  58. -----------------------------------------
  59. Lawrence Kirby | fred@genesis.demon.co.uk
  60. Wilts, England | 70734.126@compuserve.com
  61. -----------------------------------------
  62.